import { NInfiniteScroll, type InfiniteScrollProps } from "naive-ui";
import type { OmitHTMLAttributes } from "../types";

export type InfiniteScrollFactoryConstructorType = {
  props?: InfiniteScrollProps;
  attrs?: OmitHTMLAttributes<"onLoad">;
};

export class InfiniteScrollFactory {
  private props: InfiniteScrollProps = {};
  private attrs: OmitHTMLAttributes<"onLoad"> = {};

  constructor(data?: InfiniteScrollFactoryConstructorType) {
    if (data?.props) this.setProps(data.props);
    if (data?.attrs) this.setAttrs(data.attrs);
  }

  setProps(props: InfiniteScrollProps) {
    this.props = props;
    return this;
  }

  setAttrs(attrs: OmitHTMLAttributes<"onLoad">) {
    this.attrs = attrs;
    return this;
  }

  create() {
    return <NInfiniteScroll {...this.props} {...this.attrs}></NInfiniteScroll>;
  }
}
